package com.aviation.sell_ticket.mapper;

import com.aviation.sell_ticket.pojo.Aviation_airport;
import com.aviation.sell_ticket.pojo.Aviation_flight;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.security.PublicKey;
import java.time.LocalDate;
import java.util.List;

@Mapper
public interface FlightMapper {

    @Select("<script>select flight_id,flight_name,departure_time,arrival_time,time_difference,initial_time,model_id,aviation_rotate from aviation_flight where " +
            "airport_setout in <foreach item='item' index='index' collection='departureId' open='(' separator=',' close=')'>#{item.airport_id}</foreach> and " +
            "airport_arrive in <foreach item='item' index='index' collection='destinationId' open='(' separator=',' close=')'>#{item.airport_id}</foreach>" +
            "</script>")
    public List<Aviation_flight> getFlight(@Param("departureId") List<Aviation_airport> departureId, @Param("destinationId")List<Aviation_airport> destinationId);

    @Select("<script>select DISTINCT a.airport_arrive from aviation_flight as a,aviation_flight as b where " +
            "a.airport_setout in <foreach item='item' index='index' collection='departureId' open='(' separator=',' close=')'>#{item.airport_id}</foreach> and " +
            "b.airport_arrive in <foreach item='item' index='index' collection='destinationId' open='(' separator=',' close=')'>#{item.airport_id}</foreach> " +
            "and a.airport_arrive=b.airport_setout" +
            "</script>")
    public List<Integer> transferAirportQuery(@Param("departureId") List<Aviation_airport> departureId, @Param("destinationId")List<Aviation_airport> destinationId);

    @Select("select flight_id,flight_name,airport_setout,airport_arrive,departure_time,arrival_time,time_difference,initial_time,model_id,aviation_rotate from aviation_flight where flight_id=#{flightId}")
    public Aviation_flight verifyRoute(@Param("flightId")String flightId);

    @Select("select flight_name from aviation_flight where flight_id=#{flightId}")
    public String flightNumber(@Param("flightId")String flightId);

    @Select("<script>select flight_id,flight_name,departure_time,arrival_time,time_difference,initial_time,model_id,aviation_rotate from aviation_flight where airport_setout in <foreach item='item' index='index' collection='departureId' open='(' separator=',' close=')'>#{item}</foreach> and " +
            "airport_arrive in <foreach item='item' index='index' collection='destinationId' open='(' separator=',' close=')'>#{item}</foreach></script>")
    public List<Aviation_flight> flightMap(@Param("departureId") List<Integer> departureId, @Param("destinationId")List<Integer> destinationId);

}
